package com.sayice.robotconflict.game;

import com.sayice.robotconflict.game.object.GameRoom;
import com.sayice.robotconflict.game.object.Player;
import com.sayice.robotconflict.game.object.TeamRoom;
import com.sayice.robotconflict.game.object.group.PlayerGroup;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 游戏
 *
 * @author shubing
 */
public class Game {
    /**
     * 最大组队房间号
     */
    public static final AtomicInteger MAX_TEAM_ROOM_ID = new AtomicInteger();
    
    /**
     * 最大游戏房间号
     */
    public static final AtomicInteger MAX_GAME_ROOM_ID = new AtomicInteger();
    
    /**
     * 在线玩家组
     */
    public static final PlayerGroup PLAYER_GROUP = new PlayerGroup();
    
    /**
     * 临时退出玩家 map
     */
    public static final Map<String, Player> TEMP_QUIT_PLAYER_MAP = new ConcurrentHashMap<>(16);
    
    /**
     * 组队房间 map
     */
    public static final Map<Integer, TeamRoom> TEAM_ROOM_MAP = new ConcurrentHashMap<>(16);
    
    /**
     * 游戏房间 map
     */
    public static final Map<Integer, GameRoom> GAME_ROOM_MAP = new ConcurrentHashMap<>(16);
    
    /**
     * 最大对局时长 (毫秒)
     */
    public static final int MAX_GAME_TIME = 30 * 60 * 1000;
    
    /**
     * 对局中的一个时间周期时长 (毫秒)
     */
    public static final int TICK_TIME = 15;
    
    /**
     * 设计高度
     */
    public static final int DESIGN_HEIGHT = 1000;
    
    /**
     * 设计宽度
     */
    public static final int DESIGN_WIDTH = DESIGN_HEIGHT * 2;
    
    /**
     * 玩家最多携带的机器人数量
     */
    public static final int MAX_CARRY = 5;
    
    /**
     * 能量塔大小
     */
    public static final int TOWER_SIZE = 100;
    
    /**
     * 能量塔最大血量
     */
    public static final int TOWER_MAX_BLOOD = 500;
    
    /**
     * 能量塔能量半径
     */
    public static final int TOWER_ENERGY_RADIUS = 250;
    
    /**
     * 能量塔能量半径的平方
     */
    public static final int SQR_TOWER_ENERGY_RADIUS = TOWER_ENERGY_RADIUS * TOWER_ENERGY_RADIUS;
    
    /**
     * 能量塔能量值
     */
    public static final int TOWER_ENERGY_VALUE = 2;
    
    /**
     * 机器人大小
     */
    public static final int ROBOT_SIZE = 100;
    
    /**
     * 机器人最大血量
     */
    public static final int ROBOT_MAX_BLOOD = 500;
    
    /**
     * 机器人最大 x 坐标
     */
    public static final int ROBOT_MAX_POS_X = DESIGN_WIDTH - ROBOT_SIZE;
    
    /**
     * 机器人最大 y 坐标
     */
    public static final int ROBOT_MAX_POS_Y = DESIGN_HEIGHT - ROBOT_SIZE;
    
    /**
     * 机器人最大速度
     */
    public static final double ROBOT_MAX_SPEED = 2;
    
    /**
     * 机器人攻击半径
     */
    public static final int ROBOT_ATTACK_RADIUS = 250;
    
    /**
     * 机器人攻击半径的平方
     */
    public static final int SQR_ROBOT_ATTACK_RADIUS = ROBOT_ATTACK_RADIUS * ROBOT_ATTACK_RADIUS;
    
    /**
     * 两个矩形盒体是否发生碰撞
     * <p> 参数说明：</p>
     * 矩形1左上角、右下角坐标：(x11, y11)、(x12, y12) <p>
     * 矩形2左上角、右下角坐标：(x21, y21)、(x22, y22)
     *
     * @return true表示发送碰撞，false表示未发生碰撞
     */
    public static boolean collided(double x11, double y11, double x12, double y12,
                                   double x21, double y21, double x22, double y22) {
        return x12 > x21 && x22 > x11 && y12 > y21 && y22 > y11;
    }
}
